package com.dingceng.demo.photo

import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.dingceng.demo.base.BaseApplication
import com.dingceng.demo.base.dp
import com.dingceng.demo.base.screenWidth
import com.dingceng.demo.base.show
import com.dingceng.demo.photo.net.SplashTraitData

class PhotoAdapter: BaseQuickAdapter<SplashTraitData, BaseViewHolder>(R.layout.item_photo) {

    private var width = 0

    init {
        width = (BaseApplication.getIns().screenWidth - 25.dp) / 2
    }


    override fun convert(holder: BaseViewHolder, item: SplashTraitData) {
        val tvTrait = holder.getView<TextView>(R.id.tv_trait)
        val tvNameCity = holder.getView<TextView>(R.id.tv_name_city)
        val iv = holder.getView<ImageView>(R.id.iv)
        tvTrait.text = item.feature_name
        tvNameCity.text = "成都"
        val layoutParams = iv.layoutParams
        val scale = item.height.toFloat() / item.width
        var height = (width * scale).toInt()
        if (height <= 0) {
            height = width
        } else if (height > width * 2.5) {
            height = (width * 2.5).toInt()
        }
        layoutParams.height = height
        iv.layoutParams = layoutParams
        iv.show(item.content,20.dp)

    }
}